package net.pragyah.scalby.inference.exact

import net.pragyah.scalby.Variable
import scala.collection.mutable.Map

object VertexTag{
  def apply[A](variable:Variable[A]) = new VertexTag[A](variable)
}

class VertexTag[A](val variable:Variable[A]){

  val lambda = Map[A,float]()
  val pi = Map[A,float]()
  val P = Map[A,float]() //Probability of the variable given 'a' ... list of known values of some variables
  
  
  
  variable.values.foreach( a => {
    lambda(a) = 1  //initial_tree ..... lambda for leafnodes = 1 .. why? becuase lambda(x) = P(descendant-values|x) = P(null-set-for-leaf|x) = 1 
                    //lambda for non leafnodes is the product of lambda-msgs coming to it that are all 1
                   // why? consider this .... 
                  //  L has children C and D.. L has values l1 and l2 and C has values c1 and c2 and D has values d1 and d2 (C and D are leaf nodes)
                   //.... let P(c1|l1) = 0.6 and P(c2|l1) = 0.4
                           // now lambda-Message lambdaC(l1) =  P(c1|l1)*lambda(c1) + P(c2|l1)*lambda(c2) 
                           // now that C1 and C2 are leaf nodes .. their lambda values are 1 ... so lambdaC(l1) =P(c1|l1)*1 + P(c2|l1)*1 = 0.6 + 0.4 = 1
                           //This is universal and applies to all the children of L ... and of any node .... (sam applies to L-D)
                           // lambda(l1) is the product of all the lambda messages coming from L's children .. lambda(l1) = lambdaC(l1) * lambdaD(l1) = 1*1 = 1
                           // hence we can safely assume that all the lambda-values are 1 to begin with.
                           }
  )
  
}  
